
import java.util.Iterator;

public class StudentStringTransformer extends StudentTransformer<String> {
	
	private String studentPrefix;

	public StudentStringTransformer() {
		this(null);
	}
	
	public StudentStringTransformer(String studentPrefix) {
		super(false);
		if(studentPrefix == null) {
			this.studentPrefix = "";
		} else {
			this.studentPrefix = studentPrefix;
		}
	}

	@Override
	public String transform(Student input) {
		if(input == null) {
			throw new IllegalArgumentException("Parameter 'student' can not be null!");
		}
		StringBuilder sb = new StringBuilder();
		
		sb.append(getStudentPrefix());
		sb.append(input.getMatrikelNr());
		sb.append(" ");
		sb.append(input.getStudentName());
		
		return sb.toString();
	}

	@Override
	public String transform(Iterable<Student> input) {
		if(input == null) {
			throw new IllegalArgumentException("Parameter 'input' can not be null!");
		}
		StringBuilder sb = new StringBuilder();
		
		Student current;
		Iterator<Student> it = input.iterator();
		while(it.hasNext()) {
			current = it.next();
			sb.append(this.transform(current));
			if(it.hasNext()) {
				sb.append("\n");
			}
		}
		
		return sb.toString();
	}

	public String getStudentPrefix() {
		return studentPrefix;
	}

	public void setStudentPrefix(String studentPrefix) {
		this.studentPrefix = studentPrefix;
	}

}
